package dk.sensobyg.reader;

import java.io.IOException;
import java.net.URI;
import java.util.List;

import dk.sensobyg.base.AbstractWrapper;
import dk.sensobyg.base.Collector;
import dk.sensobyg.base.Configuration;
import dk.sensobyg.base.SensorData;

public class FileStorageWrapper extends AbstractWrapper {

	public FileStorageWrapper(Collector collector) {
		super(collector);
	}
	
	public void run() {
		System.out.println("file-storage running");
		System.out.println("uri " + getURI());
		URI uri = getURI();
		System.out.println("path = " + uri.getSchemeSpecificPart());
		String path = uri.getSchemeSpecificPart();
		path = path.substring(2, path.length());
		System.out.println("name = " + path);
		
		SensorDataReader reader = new SensorDataReader();
		try {
			List<SensorData> datas = reader.read(path);
			while (!datas.isEmpty()) {
				SensorData data = datas.remove(0);
				collector.newData(data);
				try {
					Thread.sleep(300);
				} catch (InterruptedException e) {
					
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void configure(Configuration configuration) {
		
	}
}
